#include "baseinfo.h"

BaseInfo::BaseInfo(QWidget *parent) : QWidget(parent)
{
    //构建“显示用户详细资料”左侧部分控件创建及布局
    UserNameLabel = new QLabel(tr("User:"));
    UserNameLineEdit = new QLineEdit;
    NameLabel = new QLabel(tr("Name:"));
    NameLineEdit = new QLineEdit;
    SexLabel = new QLabel(tr("Sex:"));
    SexComboBox = new QComboBox;
    SexComboBox->addItem(tr("Man"));
    SexComboBox->addItem(tr("Woman"));
    DepartmentLabel = new QLabel(tr("Department:"));
    DepartmentTextEdit = new QTextEdit;
    AgeLabel = new QLabel(tr("Age:"));
    AgeLineEdit = new QLineEdit;
    OtherLabel = new QLabel(tr("Other:"));
    OtherLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

    //新建左侧布局管理器，将前面创建好的控件添加到布局管理器中对应坐标的部分。
    LeftLayout = new QGridLayout();
    LeftLayout->addWidget(UserNameLabel, 0, 0);
    LeftLayout->addWidget(UserNameLineEdit, 0, 1);
    LeftLayout->addWidget(NameLabel, 1, 0);
    LeftLayout->addWidget(NameLineEdit, 1, 1);
    LeftLayout->addWidget(SexLabel, 2, 0);
    LeftLayout->addWidget(SexComboBox, 2, 1);
    LeftLayout->addWidget(DepartmentLabel, 3, 0);
    LeftLayout->addWidget(DepartmentTextEdit, 3, 1);
    LeftLayout->addWidget(AgeLabel, 4, 0);
    LeftLayout->addWidget(AgeLineEdit, 4, 1);
    LeftLayout->addWidget(OtherLabel, 5, 0, 1, 2);
    LeftLayout->setColumnStretch(0,1);
    LeftLayout->setColumnStretch(1,3);

    //构建“显示用户详细资料”右侧部分控件创建及布局
    HeadLabel = new QLabel(tr("Head:"));
    HeadIconLabel = new QLabel;
    QPixmap icon("312.png");
    HeadIconLabel->setPixmap(icon);
    HeadIconLabel->resize(icon.width(), icon.height());
    UpdateHeadBtn = new QPushButton(tr("Update"));
    TopRightLayout = new QHBoxLayout();
    TopRightLayout->setSpacing(20);
    TopRightLayout->addWidget(HeadLabel);
    TopRightLayout->addWidget(HeadIconLabel);
    TopRightLayout->addWidget(UpdateHeadBtn);
    IntroductionLabel = new QLabel(tr("Introduction:"));
    IntroductionTextEdit = new QTextEdit;
    //新建右侧布局管理器，将右侧需要的控件添加到布局管理器中对应坐标的部分。
    RightLayout = new QVBoxLayout();
    RightLayout->setMargin(10);
    RightLayout->addLayout(TopRightLayout);
    RightLayout->addWidget(IntroductionLabel);
    RightLayout->addWidget(IntroductionTextEdit);

    //新建整个界面全局布局管理器，将完成基本设置，将左侧布局和右侧布局添加进来完成全局布局显示。
    QGridLayout *mainLayout = new QGridLayout(this);
    mainLayout->setMargin(15);//设置控件与窗体的左右边距
    mainLayout->setSpacing(10);//设置各个控件之间的上下间距
    mainLayout->addLayout(LeftLayout, 0, 0);
    mainLayout->addLayout(RightLayout, 0, 1);
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
}
